//<my-matriculator - a simple tool for registering racers in a USAC cyclocross race>
//Copyright (C) <2011>  <Steven Rivers>

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System.ComponentModel;

namespace Registration.Model.Entities
{
    public class Mapping : INotifyPropertyChanged
    {
        private int _categoryid;
        public int CategoryId
        {
            get { return _categoryid; }
            set
            {
                _categoryid = value;
                OnPropertyChanged(new PropertyChangedEventArgs("CategoryId"));
            }
        }

        private string _racename;
        public string RaceName
        {
            get { return _racename; }
            set
            { 
                _racename = value;
                OnPropertyChanged(new PropertyChangedEventArgs("RaceName"));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
       
        public void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }


        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Mapping)) return false;
            return Equals((Mapping) obj);
        }

        public Mapping(string name, int id)
        {
            RaceName = name;
            CategoryId = id;
        }

        public bool Equals(Mapping other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other._categoryid == _categoryid && Equals(other._racename, _racename);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return (_categoryid*397) ^ (_racename != null ? _racename.GetHashCode() : 0);
            }
        }
    }
}